<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
<table class="layui-hide" id="test"></table>


<button class="layui-btn" onclick="addCoupons()">添加优惠券</button>
<input type="hidden" id="orgId" name="orgId" value="${orgId}">
<table class="layui-table" lay-data="{width: 1540, height:600, url:'/marketing/couponsData?activityId=${activityId}', page:true, id:'idTest'}"
       lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{field:'id', width:80,  fixed: true}">ID</th>
        <th lay-data="{field:'name', width:180}">优惠券名称</th>
        <th lay-data="{field:'mixMoney', width:120, }">最低额度</th>
        <th lay-data="{field:'money', width:120}">优惠券金额</th>
        <th lay-data="{field:'price', width:120}">售卖价格</th>
        <th lay-data="{field:'startTime', width:160}">有效期开始时间</th>
        <th lay-data="{field:'endTime', width:160}">有效期结束时间</th>
        <th lay-data="{field:'giveTypeStr', width:160}">优惠券类型</th>
        <th lay-data="{field:'remark', width:200, }">备注</th>
        <th lay-data="{fixed: 'right', width:225, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj);
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){//
                //layer.alert('编辑行：<br>'+ JSON.stringify(data));
                $.cookie("couponsDate",JSON.stringify(data));
                layer.open({
                    type: 2,
                    title:"优惠券信息",
                    shadeClose:true,
                    area: ['65%', '90%'],
                    content: '/marketing/goVoucherEdit?orgId=${orgId}&activityId=${activityId}',
                    end:function () {
                        window.location.reload();
                    }
                });
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('idTest')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('idTest');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

function addCoupons() {
    $.cookie("couponsDate",null);
    layer.open({
        type: 2,
        title:"优惠券信息",
        shadeClose:true,
        area: ['90%', '90%'],
        content: '/marketing/goVoucherEdit?orgId=${orgId}&activityId=${activityId}',
        end:function () {
            window.location.reload();
        }
    });
}

</script>





</body>
</html>
